package com.info3k.client.components;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.info3k.client.Info3K;
import com.info3k.client.commands.event.ShowEventCommand;
import com.info3k.client.domain.Event;

public class EventRenderer extends Composite {
	
	private Event event;

	private VerticalPanel panel = new VerticalPanel();
	
	public EventRenderer(final Event event, final Info3K info){
		this.setEvent(event);
		initWidget(panel);
		panel.setWidth("100%");
			
		HTML html = new HTML("<h1>" + event.getTitle() + "</h1>");
		panel.add(html);
		
		panel.add(new HTML("<div class=\"h_line\"></div>"));
		
		html.getElement().getStyle().setProperty("cursor", "pointer");
		html.addClickHandler(new ClickHandler(){
			public void onClick(ClickEvent e) {
				ShowEventCommand cmd = new ShowEventCommand(RootPanel.get("right_section"), info, event);
				cmd.execute();				
			}
		});
		
		String text = event.getDescription();
		if(text.length()>600) text = text.substring(0, 600) + "...";
		
		panel.add(new HTML(text));
	}

	public Event getEvent() {
		return event;
	}

	public void setEvent(Event event) {
		this.event = event;
	}
}
